﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace MyAttribute.Extend
{
    public static class DescriptionManager
    {
        /// <summary>
        /// 静态类中的静态方法，方法的第一个参数用this 修饰---扩展方法
        /// </summary>
        /// <param name="oValue"></param>
        /// <returns></returns>
        public static string GetDescription(this Enum oValue)
        {
            FieldInfo field = oValue.GetType().GetField(oValue.ToString());
            if (field.IsDefined(typeof(RemarkAttribute), true))
            {
                RemarkAttribute attribute = field.GetCustomAttribute<RemarkAttribute>();
                string description = attribute.GetDescription();
                Console.WriteLine(description);
                return description;
            }
            else
            {
                return oValue.ToString();
            }

        }
    }
}
